<template>
	<view class='wrapp'>
		<view class='item'>
			<view>
				<view class='itemTitle'>
					<text>平台算力</text>
					<view @tap='toPower'>
						<text>{{platformPowerInfo.powerTotal}}</text>
						<!-- <text class='small'>MB</text> -->
						<image src='../../static/assets/right.png' class='right'></image>
					</view>
				</view>
				<view class='itemContent'>
					<text>平台算力排行</text>
					<text class='itemContentNum'>{{platformPowerInfo.powerTopIndex}}</text>
				</view>
				<view class='itemContent'>
					<text>昨日获得算力</text>
					<text class='itemContentNum'>{{platformPowerInfo.yesterdayAddPowerCount}}</text>
				</view>
				<view class='itemContent' style='border-bottom:0px solid'>
					<text>累计获得收益</text>
					<text class='itemContentNum'>{{platformPowerInfo.platformProfitCount}}</text>
				</view>
			</view>
			<view v-if="isPlatformMaskShow" class='noContent'>
				<image src='../../static/assets/noMore.png' class='noMore'></image>
				<text class='noWord'>您还没有任何算力哦～</text>
			</view>
		</view>

		<view class='item' style='height:136px;'>
			<view>
				<view class='itemTitle'>
					<text>项目算力</text>
					<view>
						<text>{{projectPowerInfo.projectPower}}</text>
					</view>
				</view>
				<view class='itemContent'>
					<text>项目总收益</text>
					<text class='itemContentNum'>{{projectPowerInfo.projectProfitCount}}</text>
				</view>
				<view class='itemContent' style='border-bottom:0px solid'>
					<text>已分得收益</text>
					<text class='itemContentNum'>{{projectPowerInfo.ownerProfitCount}}</text>
				</view>
			</view>
			<view v-if="isProjectMaskShow" class='noContent'>
				<image src='../../static/assets/noMore.png' class='noMore'></image>
				<text class='noWord'>您还没有任何项目哦～</text>
			</view>
		</view>

		<view class='item' style='height:136px;'>
			<view>
				<view class='itemTitle'>
					<text>设备总数</text>
					<view @tap='toMiners'>
						<text>{{minerInfo.minerCount}}</text>
						<text class='small'>台</text>
						<image src='../../static/assets/right.png' class='right'></image>
					</view>
				</view>
				<view class='itemContent'>
					<text>累计收益</text>
					<text class='itemContentNum'>{{minerInfo.minerProfitCount}}</text>
				</view>
				<view class='itemContent' style='border-bottom:0px solid'>
					<text>每天平均收益</text>
					<text class='itemContentNum'>{{minerInfo.averageProfitCount}}</text>
				</view>
			</view>
			<view v-if="isMinerMaskShow" class='noContent'>
				<image src='../../static/assets/noMore.png' class='noMore'></image>
				<text class='noWord'>您还没有任何设备哦～</text>
			</view>
		</view>
	</view>
</template>
<script>
	import api from '../../common/apis.js'
	import message from '../../common/message.js'
	import util from '../../common/util.js'
	export default {
		data() {
			return {
				//平台算力
				platformPowerInfo: {},
				isPlatformMaskShow: false,
				//项目算力
				projectPowerInfo: {},
				isProjectMaskShow: false,
				//设备总数
				minerInfo: {},
				isMinerMaskShow: false
			}
		},
		onLoad: function(options) {
// 			uni.setStorage({
// 				key: 'authorization',
// 				data: 'eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIyMCIsImF1dGgiOiJST0xFX1VTRVIiLCJleHAiOjE1NTMwNDY1MDB9.jxXBiJrQFbBjvq_8sNiCOAmYRc_8X4Ydt7Kw2b0FdgLfcAaczOjn-oyakd4XwsLctGCcBCJx7ByRFPrLxFBUmg',
// 				success: function() {
// 					console.log('success');
// 				}
// 			});
			this.getPlatform();
			this.getProject();
			this.getDevice();
		},

		onPullDownRefresh: function() {
			this.getPlatform();
		},
		methods: {
			getPlatform() {
				let token = uni.getStorageSync("authorization");
				uni.showLoading({
					title: "加载中"
				});
				uni.request({
					url: api.platformApi,
					method: "get",
					header: {
						Authorization: "Bearer " + token
					},
					success: res => {
						uni.hideLoading();
						if (res.statusCode == "200") {
							console.log((res.data))
							this.platformPowerInfo = res.data
						} else {
							let r = util.errHandler(res)
							if (r == true) {
								this.isPlatformMaskShow = true
							}
						}
						this.getProject();
					}
				});
			},
			getProject() {
				let token = uni.getStorageSync("authorization");
				uni.showLoading({
					title: "加载中"
				});
				uni.request({
					url: api.projectApi,
					method: "get",
					header: {
						Authorization: "Bearer " + token
					},
					success: res => {
						uni.hideLoading();
						if (res.statusCode == "200") {
							this.projectPowerInfo = res.data
						} else {
							let r = util.errHandler(res)
							if (r == true) {
								this.isProjectMaskShow = true
							}
						}
						this.getDevice();
					}
				});
			},
			getDevice() {
				let token = uni.getStorageSync("authorization");

				uni.showLoading({
					title: "加载中"
				});
				uni.request({
					url: api.deviceApi,
					method: "get",
					header: {
						Authorization: "Bearer " + token
					},
					success: res => {
						uni.hideLoading();
						uni.stopPullDownRefresh()
						if (res.statusCode == "200") {
							this.minerInfo = res.data
						} else {
							let r = util.errHandler(res)
							if (r == true) {
								this.isMinerMaskShow = true
							}
						}
					}
				});
			},

			//页面导航
			toMiners() {
				uni.navigateTo({
					url: '/pages/minerList/minerList'
				})
			},
			toPower() {
				uni.navigateTo({
					url: '/pages/power/power'
				})
			}
		}
	}
</script>

<style>
	.wrapp {
		padding-bottom: 20px;
	}

	.item {
		width: 92.04%;
		height: 176px;
		margin: 0 auto;
		background: rgba(238, 238, 238, 1);
		box-shadow: 0px 2px 4px 0px rgba(153, 153, 153, 0.5);
		border-radius: 8px;
		margin-top: 30px;
		font-size: 24px;
		font-family: PingFangSC-Medium;
		font-weight: 500;
		position: relative;
	}

	.noContent {
		position: absolute;
		top: 0;
		bottom: 0;
		left: 0;
		right: 0;
		background: rgba(238, 238, 238, 0.85);
		z-index: 999;
		text-align: center;
	}

	.noMore {
		margin-top: 40px;
		width: 78px;
		height: 64px;
	}

	.noWord {
		display: block;
		font-size: 14px;
		font-family: PingFangSC-Medium;
		font-weight: 500;
		color: rgba(0, 0, 0, 1);

	}

	.right {
		width: 25px;
		height: 25px;
	}

	.itemTitle {
		height: 48px;
		line-height: 48px;
		border-bottom: 1px solid rgba(153, 153, 153, 0.3);
		padding: 0 10px 0 10px;
		width: 90%;
		margin: 0 auto;
		display: flex;
		justify-content: space-between;
	}

	.small {
		font-size: 12px;
		font-family: PingFangSC-Medium;
		font-weight: 500;
		color: rgba(51, 117, 253, 0.3);
		margin-left: 5px;
	}

	.itemTitle view {
		color: rgba(51, 117, 253, 1);
	}

	.itemContent {
		height: 38px;
		line-height: 38px;
		border-bottom: 1px solid rgba(153, 153, 153, 0.3);
		padding: 0 10px 0 10px;
		width: 90%;
		margin: 0 auto;
		display: flex;
		justify-content: space-between;
		font-size: 12px;
		font-family: PingFangSC-Medium;
		font-weight: 500;
		color: rgba(51, 51, 51, 1);
	}

	.itemContentNum {
		font-size: 18px;
		font-family: PingFangSC-Medium;
		font-weight: 500;
		color: rgba(51, 117, 253, 1);
		margin-right: 25px;
	}
</style>
